package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.CostRate;
import cn.xscrum.demo.service.ICostRateService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 换乘费用占比分析Controller
 * 
 * @author xscrum
 * @date 2020-11-29
 */
@Controller
@RequestMapping("/rohepaper/CostRate")
public class CostRateController extends BaseController
{
    private String prefix = "rohepaper/CostRate";

    @Autowired
    private ICostRateService costRateService;

    @RequiresPermissions("rohepaper:CostRate:view")
    @GetMapping()
    public String CostRate()
    {
        return prefix + "/CostRate";
    }

    /**
	 * 查询换乘费用占比分析列表
     */
    @RequiresPermissions("rohepaper:CostRate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CostRate costRate)
    {
        startPage();
        List<CostRate> list = costRateService.selectCostRateList(costRate);
        return getDataTable(list);
    }

    /**
	 * 导出换乘费用占比分析列表
     */
    @RequiresPermissions("rohepaper:CostRate:export")
    @Log(title = "换乘费用占比分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CostRate costRate)
    {
        List<CostRate> list = costRateService.selectCostRateList(costRate);
        ExcelUtil<CostRate> util = new ExcelUtil<CostRate>(CostRate.class);
        return util.exportExcel(list, "CostRate");
    }

    /**
	 * 新增换乘费用占比分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存换乘费用占比分析
     */
    @RequiresPermissions("rohepaper:CostRate:add")
    @Log(title = "换乘费用占比分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CostRate costRate)
    {
        return toAjax(costRateService.insertCostRate(costRate));
    }

    /**
	 * 修改换乘费用占比分析
     */
    @GetMapping("/edit/{no8}")
    public String edit(@PathVariable("no8") Long no8, ModelMap mmap)
    {
        CostRate costRate = costRateService.selectCostRateById(no8);
        mmap.put("costRate", costRate);
        return prefix + "/edit";
    }

    /**
	 * 修改保存换乘费用占比分析
     */
    @RequiresPermissions("rohepaper:CostRate:edit")
    @Log(title = "换乘费用占比分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CostRate costRate)
    {
        return toAjax(costRateService.updateCostRate(costRate));
    }

    /**
	 * 删除换乘费用占比分析
     */
    @RequiresPermissions("rohepaper:CostRate:remove")
    @Log(title = "换乘费用占比分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(costRateService.deleteCostRateByIds(ids));
    }
}
